/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.dnd.transfer;

import de.mnit.basis.crypt.JavaBase64;

/**
 * @author Michael Nitsche
 * 14.06.2010	Erstellt
 */
public class TextFormatObjekt {

	public final String text;
	public final String format;

	public TextFormatObjekt(String text, String format) {
		this.text=text;
		this.format=format;
	}


	public static Object zuByteArray(TextFormatObjekt tfo) {
		StringBuilder sb=new StringBuilder();
		sb.append(JavaBase64.verschluesseln(tfo.text.getBytes()));
		sb.append(" ");
		sb.append(JavaBase64.verschluesseln(tfo.format.getBytes()));
		return sb.toString().getBytes();
	}

	public static TextFormatObjekt zuObjekt(byte[] ba) {
		String s=new String(ba);
		String[] sa=s.split(" ");
		String text  =JavaBase64.entschluesselnString(sa[0]);
		String format=JavaBase64.entschluesselnString(sa[1]);
		return new TextFormatObjekt(text, format);
	}

	public String toString() {
		return text+"\n"+format;
	}

}
